<?php
/**
 * 在线订单后台管理栏目修改文件
 *
 * @author		Arthur(ArthurXF@gmail.com)
 * @copyright	(c) 2006 by bizeway.com
 * @version		$Id$
 * @package		ArthurXF
 * @subpackage	deal
 */
require_once('../config/config.inc.php');
require_once("../class/deal.class.php");
require_once ('../..'.__WEBADMIN_ROOT.'/checklogin.php');

$objWebInit = new deal();
//数据库连接参数
$objWebInit->setDBG($arrGPdoDB);
//smarty参数
$objWebInit->arrGSmarty = $arrGSmarty;
//图片上传参数
$objWebInit->arrGPic = $arrGPic;
$objWebInit->db();

//访问权限检查
if (! $objWebInit->checkPopedomG($_SESSION['user_id'])) {
	check::AlertExit('对不起，您没有权限访问此页',-1);
}

// 修改订单状态
if (!empty($_POST['deal_no'])) {			
	$deal_no = trim($_POST['deal_no']);
	$type_id = intval($_POST['type_id']);	
	if(empty($deal_no)) {
		AlertExit('访问失败 (deal no error)',-1);
	}
	if (!in_array($type_id, array_keys($arrMType))) {
		AlertExit('访问失败 (type_id code error)',-1);
	}
	
	$arrUpdate = array();
	$objWebInit->updateDeal(array('deal_no'=>$deal_no,'type_id'=>$type_id));
	
	check::AlertExit('修改成功',-1);
	exit();
}

// 取得文章信息
$arrInfo = $objWebInit->getInfo($_REQUEST['id']);

if ($_SERVER["REQUEST_METHOD"] == "POST"){



	if(strpos($_POST['type_id'],'|')!==false){
		$arrTemp = explode('|',$_POST['type_id']);
		$_POST['type_id'] = $arrTemp[0];
		$_POST['type_roue_id'] = $arrTemp[1];
	}else{
		$_POST['type_roue_id'] = ':'.$_POST['type_id'].':';
	}
	if($_POST['summary'] == '') $_POST['summary'] = check::csubstr(trim(str_replace("&nbsp;"," ",str_replace("\r\n","",strip_tags($_POST['intro'])))),0,$arrGWeb['db_summary_len']);
	if($_POST['title'] != '') $_POST['title_md5'] = md5($_POST['title']);
	$_POST['thumbnail'] = $_POST['photo'];

	#自动拆字生成tag
	if(empty($_POST['tag'])){
		$objSP = new SplitWord();
		$_POST['tag'] = $objSP->SplitRMM($_POST['title'],false);
	}

	$_POST = array_merge($arrInfo,$_POST);
	$objWebInit->saveInfo($_POST,1);

	$objWebInit->updateCache($_POST['id'],$_POST['type_id'],$arrMOutput);

	check::WindowLocation('index.php','page='.$_GET['page']);
}

if(!is_array($arrMType)||empty($arrMType)){
	$arrMType = $objWebInit->getTypeList();
	$arrMType = $objWebInit->formatTypeList(0,$arrMType);
}

//========================================
//计算总价格或者总积分
$intBonus = 0;
foreach($arrInfo['product'] as $k=>$v){
	$intBonus = $intBonus + $v['product_price']*$v['product_count'];
}
$arrInfo['intBonus'] = $intBonus;
//========================================

//print_r($arrInfo);
// 输出到模板
$arrMOutput["template_file"] = "admin.html";
$arrMOutput["smarty_assign"]['FileCallPath'] = $objWebInit->arrGPic['FileCallPath'];
$arrMOutput["smarty_assign"]['FileListPicSize'] = $objWebInit->arrGPic['FileListPicSize'];
$arrMOutput["smarty_assign"]['arrData'] = $arrInfo;
$arrMOutput["smarty_assign"]['arrMType'] = $arrMType;
$arrMOutput["smarty_assign"]['action_type'] = "save";
$arrMOutput["smarty_assign"]['MAIN'] = $arrGSmarty['admin_main_dir'].'detail.htm';
$objWebInit->output($arrMOutput);
?>